package com.ruoyi.web.controller.personal;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.YcPersonal;
import com.ruoyi.service.IYcPersonalService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 个人信息Controller
 *
 * @author 杨琛
 * @date 2020-09-10
 */
@Controller
@RequestMapping("/ruoyi/personal")
public class YcPersonalController extends BaseController {
    private String prefix = "ruoyi/personal";

    @Autowired
    private IYcPersonalService ycPersonalService;

    @RequiresPermissions("ruoyi:personal:view")
    @GetMapping()
    public String personal() {
        return prefix + "/personal";
    }

    /**
     * 查询个人信息列表
     */
    @RequiresPermissions("ruoyi:personal:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YcPersonal ycPersonal) {
        startPage();
        ycPersonal.setuId(ShiroUtils.getUserId());
        List<YcPersonal> list = ycPersonalService.selectYcPersonalList(ycPersonal);
        return getDataTable(list);
    }

    /**
     * 导出个人信息列表
     */
    @RequiresPermissions("ruoyi:personal:export")
    @Log(title = "个人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YcPersonal ycPersonal) {
        List<YcPersonal> list = ycPersonalService.selectYcPersonalList(ycPersonal);
        ExcelUtil<YcPersonal> util = new ExcelUtil<YcPersonal>(YcPersonal.class);
        return util.exportExcel(list, "personal");
    }

    /**
     * 新增个人信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存个人信息
     */
    @RequiresPermissions("ruoyi:personal:add")
    @Log(title = "个人信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YcPersonal ycPersonal) {
        ycPersonal.setuId(ShiroUtils.getUserId());
        return toAjax(ycPersonalService.insertYcPersonal(ycPersonal));
    }

    /**
     * 修改个人信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        YcPersonal ycPersonal = ycPersonalService.selectYcPersonalById(id);
        mmap.put("ycPersonal", ycPersonal);
        return prefix + "/edit";
    }

    /**
     * 修改保存个人信息
     */
    @RequiresPermissions("ruoyi:personal:edit")
    @Log(title = "个人信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YcPersonal ycPersonal) {
        return toAjax(ycPersonalService.updateYcPersonal(ycPersonal));
    }

    /**
     * 删除个人信息
     */
    @RequiresPermissions("ruoyi:personal:remove")
    @Log(title = "个人信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ycPersonalService.deleteYcPersonalByIds(ids));
    }

    /**
     * 查询所有人员
     */
    @GetMapping("/all/{name}")
    @ResponseBody
    public List<YcPersonal> selectAllPersonnel(@PathVariable("name") String name) {
        return ycPersonalService.selectYcPersonalNameList(name);
    }

}
